<template>
  <div class="animated fadeIn">
    <div class="card card-accent-primary">
      <b-row>
        <b-col cols="12">
          <Card style="margin-bottom: 10px">
            <Form inline>
              <FormItem style="margin-bottom: 0">
                <Select  v-model="typeid" style="width:150px" >
                  <Option v-for="item in type" :value="item.id" :key="item.id">{{item.name}}</Option>
                </Select>
              </FormItem>
            </Form>
          </Card>
        </b-col>
      </b-row>
      <b-row>
        <b-col cols="12">
          <Card>
            <p slot="title" style="height: 32px; margin-bottom: 0">
              <Button type="primary" icon="plus-round">新增</Button>
            </p>
            <div>
              <i-table :loading="loading" border :columns="columns" :data="items"></i-table>
            </div>
          </Card>
        </b-col>
      </b-row>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      typeid: 1,
      type: [
        {
          id: 1,
          name: 'user端'
        },
        {
          id: 2,
          name: 'admin端'
        }
      ],
      key: '',
      columns: [
        {
          title: 'ID',
          key: 'id',
          width: 50
        },
        {
          title: '菜单名称',
          key: 'name',
          width: 200
        },
        {
          title: '菜单url',
          key: 'url',
          width: 200
        },
        {
          title: '分类',
          key: 'url',
          width: 200,
          render: (h, params) => {
            return h('span', {
              'class': 'badge badge-success'
            }, params.row.type === 1 ? 'user端' : 'admin端')
          }
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          className: 'table-min-width'
        }
      ],
      items: [],
      total: 0,
      page: 1,
      loading: true
    }
  },
  methods: {
    // 获取列表
    getList () {
      this.$get('/api/admin/menu', {
        params: {
          page: this.page
        }
      }).then((res) => {
        if (res) {
          this.total = res.data.total
          this.items = res.data.data
          this.loading = false
        }
      })
    }
  },
  created () {
    this.getList()
  }
}
</script>
<style>
  /*解决table表格适应问题*/
  .table-min-width {
    min-width: 200px;
    width: 200px;
  }
</style>
